package myfilter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.jasper.tagplugins.jstl.core.Out;

public class loginFilter implements Filter {

	@Override
	public void destroy() {
		// TODO 自动生成的方法存根

	}

	@Override
	public void doFilter(ServletRequest rq, ServletResponse rp, FilterChain chain)
			throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest)rq;
		HttpSession session = request.getSession();
		String abc = (String)session.getAttribute("loginName");
		RequestDispatcher dispatcher = rq.getRequestDispatcher("/logout.jsp"); //设置未登录跳转的页面
		if(abc == null){
			dispatcher.forward(rq,rp);   
			System.out.print("用户未登录，不予许操作");  
			return;
		}
		chain.doFilter(rq, rp);
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO 自动生成的方法存根

	}

}
